﻿/*  
 *  IIS LogFile Analyser, Copyright (C) 2013. http://www.iis-analyser.com
 *  --
 *  This program is free software, provided "AS IS" WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
 * 
 *  File Author: Ian Quigley,    2013-02-23
 */


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using DataStore;
using System.Configuration;
using System.Web.UI.WebControls;

namespace Web
{
    public abstract class BasePage : Page
    {
        private Store _data;
        public Store Data
        {
            get
            {
                return _data ?? (_data = GetDataStore());
            }
        }
        
        public static Store GetDataStore()
        {
            return new Store( ConfigurationManager.AppSettings["dbfile"] );
        }

        public long QueryParamLong(string name)
        {
            long l;
            if (!long.TryParse(Request.QueryString[name], out l))
                l = default(long);

            return l;
        }

        protected void DropdownSelect( DropDownList drpList, string selected )
        {
            drpList.SelectedIndex = 0;

            int i = 0;
            int select = 0;
            foreach (var str in ((List<string>)drpList.DataSource))
            {
                if (str == selected)
                    select = i;
                i++;
            }
            drpList.SelectedIndex = select;
        }

        
    }
}